package com.sample.kokou;

import java.util.List;
import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.content.DialogInterface;
import android.content.Intent;

public class SampleActivity extends Activity
	implements OnClickListener {

  private List<Button> buttons = new ArrayList<Button>();
  private Button change_wall_button;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    initialize_buttons();
    change_wall_button = GenericUtil.getView(this, R.id.change_wall_button);
    change_wall_button.setOnClickListener(this);
  }

  @Override
  public void onClick(View v) {
    if (v == change_wall_button) {
      Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
      startActivity(intent);
      return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("ボタン");
    builder.setMessage("ボタン" + ((TextView) v).getText() + "が押されました!");
    builder.setPositiveButton("OK", new android.content.DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
          setResult(RESULT_OK);
        }
      });
    builder.create();
    builder.show();
  }

  private void initialize_buttons() {
    Button b;
    b = GenericUtil.getView(this, R.id.buttonA); buttons.add(b);
    b = GenericUtil.getView(this, R.id.buttonB); buttons.add(b);
    b = GenericUtil.getView(this, R.id.buttonC); buttons.add(b);
    b = GenericUtil.getView(this, R.id.buttonD); buttons.add(b);
    b = GenericUtil.getView(this, R.id.buttonE); buttons.add(b);
    b = GenericUtil.getView(this, R.id.buttonF); buttons.add(b);
    b = GenericUtil.getView(this, R.id.buttonG); buttons.add(b);
    b = GenericUtil.getView(this, R.id.buttonH); buttons.add(b);
    for(Button button: buttons ) {
      button.setOnClickListener(this);
    }
  }
}